﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NUnit.Framework;
using Alogient.Cameleon.Sdk;

namespace Alogient.Cameleon.Sdk.tests
{
    [TestFixture]
    public class StringToolsTest : FixtureBase
    {
        [SetUp]
        public void Init()
        {
        }

        [TearDown]
        public void Finish()
        {
        }

        [Test]
        public void RemoveUnusefulTags_EmptyString()
        {
            var result = StringTools.RemoveUnusefulTags(string.Empty);
            Assert.AreEqual(string.Empty, result);
        }

        [Test]
        public void RemoveUnusefulTags_HtmlContent()
        {
            var content = "content<p>&nbsp;</p>";
            var result = StringTools.RemoveUnusefulTags(content);
            Assert.AreEqual("content", result);
        }

        [Test]
        public void RemoveUnusefulTags_NullString()
        {
            var result = StringTools.RemoveUnusefulTags(null);
            Assert.IsNull(result);
        }

        [Test]
        public void FileNameEncode_WithoutExtension()
        {
            var result = StringTools.FileNameEncode("Tèst");
            Assert.AreEqual("Test", result);
        }

        [Test]
        public void FileNameEncode_WithExtension()
        {
            var result = StringTools.FileNameEncode("Tèst.abc");
            Assert.AreEqual("Test.abc", result);
        }

        [Test]
        public void Encode()
        {
            var result = StringTools.Encode("éàèùö");
            Assert.AreEqual("eaeuo", result);
        }

        [Test]
        public void EncodeChar()
        {
            var result = StringTools.EncodeChar('è');
            Assert.AreEqual("e", result);
        }

        [Test]
        [ExpectedException(typeof(System.NullReferenceException))]
        public void GetRewriteUrl1()
        {
            // TODO Have a HttpContext
            Assert.AreEqual(string.Empty, StringTools.GetRewriteUrl());
        }

        [Test]
        [ExpectedException(typeof(System.NullReferenceException))]
        public void GetRewriteUrl2()
        {
            // TODO Have a HttpContext
            Assert.AreEqual("test.aspx", StringTools.GetRewriteUrl("test.aspx"));
        }

        [Test]
        public void QueryFromSearchString_Null()
        {
            Assert.IsNull(StringTools.QueryFromSearchString(null));
        }

        [Test]
        public void QueryFromSearchString_Empty()
        {
            Assert.IsNull(StringTools.QueryFromSearchString(string.Empty));
        }

        [Test]
        public void QueryFromSearchString()
        {
            var result = StringTools.QueryFromSearchString("test");
            Assert.AreEqual(" #column# LIKE '%test%' ", result);
        }
    }
}
